package com.ruoyi.web.controller.order;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.TicketOrderInfo;
import com.ruoyi.order.mapper.TicketOrderInfoMapper;
import com.ruoyi.order.service.ITicketOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 影票订单信息Controller
 *
 * @author HHAOYU
 * @date 2020-12-18
 */
@RestController
@RequestMapping("/order/ticketOrderInfo")
public class TicketOrderInfoController extends BaseController
{
    @Autowired
    private ITicketOrderInfoService ticketOrderInfoService;

    @Autowired
    private TicketOrderInfoMapper ticketOrderInfoMapper;

    /**
     * 查询影票订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:ticketOrderInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TicketOrderInfo ticketOrderInfo)
    {
        startPage();
        List<TicketOrderInfo> list = ticketOrderInfoMapper.selectTicketOrderInfoListForAdmin(ticketOrderInfo);
        return getDataTable(list);
    }

    /**
     * 导出影票订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:ticketOrderInfo:export')")
    @Log(title = "影票订单信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TicketOrderInfo ticketOrderInfo)
    {
        List<TicketOrderInfo> list = ticketOrderInfoService.selectTicketOrderInfoList(ticketOrderInfo);
        ExcelUtil<TicketOrderInfo> util = new ExcelUtil<TicketOrderInfo>(TicketOrderInfo.class);
        return util.exportExcel(list, "ticketOrderInfo");
    }

    /**
     * 获取影票订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:ticketOrderInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ticketOrderInfoService.selectTicketOrderInfoById(id));
    }

    /**
     * 新增影票订单信息
     */
    @PreAuthorize("@ss.hasPermi('order:ticketOrderInfo:add')")
    @Log(title = "影票订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicketOrderInfo ticketOrderInfo)
    {
        return toAjax(ticketOrderInfoService.insertTicketOrderInfo(ticketOrderInfo));
    }

    /**
     * 修改影票订单信息
     */
    @PreAuthorize("@ss.hasPermi('order:ticketOrderInfo:edit')")
    @Log(title = "影票订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicketOrderInfo ticketOrderInfo)
    {
        return toAjax(ticketOrderInfoService.updateTicketOrderInfo(ticketOrderInfo));
    }

    /**
     * 删除影票订单信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:ticketOrderInfo:remove')")
    @Log(title = "影票订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ticketOrderInfoService.deleteTicketOrderInfoByIds(ids));
    }
}
